home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: tank.news.pipex.net!pipex!warwick!bsmail!talisker!nathan
- From: nathan@pact.srf.ac.uk (Nathan Sidwell)
- Subject: Re: Binary association problem
- Message-ID: <Dn2ppp.5nr@uns.bris.ac.uk>
- Sender: usenet@uns.bris.ac.uk (Usenet news owner)
- Nntp-Posting-Host: talisker.pact.srf.ac.uk
- Organization: Inmos
- X-Newsreader: TIN [version 1.2 PL2]
- References: <31296F14.88E@esec.ch>
- Date: Tue, 20 Feb 1996 12:08:12 GMT
-
- Oliver Plohmann (opl@esec.ch) wrote:
- : -------------------------a.h------------------------
-
- : class B;
-
- : class A {
-
- : int* x;
- : public:
-
- : A() {};
- : ~A() {};
-
- : void operator+(const int& i) {
- : *x=i; // protection violation !
- : };
- : };
-
- : -------------------------b.h------------------------
- : #include "a.h"
-
- : class A;
-
- : class B {
-
- : A* x;
- : public:
-
- : B() { *x=5; };
- : ~B() {};
- : };
-
- : --------------------------test.cpp--------------------
-
- : #include "b.h"
-
- : void main()
- : {
- : B b; // protection violation in A::operator=(const int& i)
- : }
-
- What it looks like your doing is the equivalent of
-
- int *a;
- *a = 5;
-
- a has not been set, so the dereference invokes undefined behaviour.
-
- nathan
- --
- Nathan Sidwell Holder of the Xmris home page
- Chameleon Architecture Group at SGS-Thomson, formerly Inmos
- http://www.pact.srf.ac.uk/~nathan/ Tel 0117 9707182
- nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
-